<?php

namespace app\api\job;

// use think\queue\Job;

use app\common\model\circle\CircleFansModel;
use app\common\model\circle\CircleModel;
use dengje\workerman\process\queue\Client as Job;
use app\common\model\NoticeModel;

class CircleJob
{
    private $process = null;

    public function fire(Job $job, $data)
    {
        CircleModel::where('id', $data['id'])->update(['update_time' => time()]);
        $content = '<div style="margin-top: 8px;background: #f5f5f5;padding: 8px;display: flex;align-items: center;border-radius: 4px;">
            <img src="' . $data['avatar'] . '" style="width: 45px;height: 45px;object-fit: cover;display: block;border-radius: 2px;">
            <div style="font-size: 12px;margin-left: 8px;">
                您关注的"' . $data['name'] . '"更新了新内容🎉，后续可前往【我的】-【圈子】随时随地查看更新。
            </div>
            </div>';
        $url = '/pages/note/circle?id=' . $data['id'];
        $uids = CircleFansModel::where('circle_id', $data['id'])->column('user_id');
        for ($i = 0; $i < count($uids); $i++) {
            (new NoticeModel)->send($uids[$i], '圈子通知', $content, 0, '', $url, 2);
        }
        $job->delete();
    }

    public function failed($data)
    {

        // ...任务达到最大重试次数后，失败了
    }
}
